package com.tueye.dao.impl.usermanager;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.tueye.base.util.BaseDao;
import com.tueye.base.util.IBaseHbnDao;
import com.tueye.base.util.Page;
import com.tueye.dao.usermanager.IRegisterDao;
import com.tueye.entity.Adinfo;
import com.tueye.entity.user.ParticularUserInfo;
import com.tueye.entity.user.User;
import com.tueye.utils.TuEyeConstant;

@SuppressWarnings("unchecked")
@Scope("prototype")
@Component("registerDao")
public class RegisterDaoImpl extends BaseDao implements IRegisterDao{
	
	private static final String User = TuEyeConstant.TUEYE_USER;
	@Autowired
	@Qualifier("baseHbnDao")
	private IBaseHbnDao  baseHbnDao;

	@Override
	public List getUserByemail(String Email) {
		// TODO Auto-generated method stub
		String hql = "from User where email =  '"+Email+"'";
		return (List) baseHbnDao.queryList(hql);
	}

	@Override
	public List getUserBybyname(String byname) {
		// TODO Auto-generated method stub
		String hql = "from User where byname =  '"+byname+"'";
		return (List) baseHbnDao.queryList(hql);
	}

	@Override
	public void saveUser(User user) {
		// TODO Auto-generated method stub
		baseHbnDao.saveOrUpdate(user);
	}

	@Override
	public List getUserLogin(String Email) {
		// TODO Auto-generated method stub
		String hql = "from User where email =  '"+Email+"' or byname= '"+Email+"'";
		return (List) baseHbnDao.queryList(hql);
	}

	@Override
	public void updateUser(User user) {
		// TODO Auto-generated method stub
		baseHbnDao.merge(user);

	}

	@Override
	public List getParticularuserinfo(String id) {
		// TODO Auto-generated method stub
		String hql = "from ParticularUserInfo where user_id =  '"+id+"'";
		return (List) baseHbnDao.queryList(hql);
	}

	@Override
	public void updateParticularUserInfo(ParticularUserInfo pu) {
		// TODO Auto-generated method stub
		baseHbnDao.saveOrUpdate(pu);
	}

	@Override
	public Page pagedQueryByHQL(String hql, int pageNo, int pageSize,
			Object... values) {
		return baseHbnDao.pagedQueryByHQL(hql, pageNo, pageSize, values);
	}

	@Override
	public void delUser(String id) {
		// TODO Auto-generated method stub
		User user =  (User) baseHbnDao.findById(User.class, id);
		baseHbnDao.delete(user);
	}

	@Override
	public User getUserById(String id) {
		// TODO Auto-generated method stub
		return (User) baseHbnDao.findById(User.class, id);
	}

	

}
